local game = require "club.threecard.baccarat"

local M = game.ui.activity()

function M:ctor()
    self.res = "club.threecard.baccarat/ui/ingame.b:ingame"

    local Seats = require "club.threecard.baccaratlib.ui.widgets.Seats"
    self.seats = Seats.new(6, "club.threecard.baccarat/ui/ingame.b:seats")

    local BetOperator = require "club.threecard.baccaratlib.ui.widgets.BetOperator"
    self.bet_operator = BetOperator.new()

    local PhaseShower = require "club.threecard.baccaratlib.ui.widgets.PhaseShower"
    self.phase_shower = PhaseShower.new()

    local Resumer = require "club.threecard.baccaratlib.ui.widgets.Resumer"
    self.resumer = Resumer.new(self)

    local Others = require "club.threecard.baccaratlib.ui.widgets.Others"
    self.others = Others.new(self.seats)

    local player_info = require "club.threecard.gamelib.widget.player_info"
    self.player_info = player_info.new()

    local BetAreas = require "club.threecard.baccaratlib.ui.gameplay.BetAreas"
    self.bet_area = BetAreas.new("club.threecard.baccarat/ui/ingame.b:bet_area")

    local BetChip = require "club.threecard.baccaratlib.ui.gameplay.BetChip"
    self.bet_chip = BetChip.new(self.bet_area, self.seats, self.others, "club.threecard.baccarat/ui/ingame.b:bet_chip")

    local bet_summarizing = game.require "ui.ingame.bet_summarizing"
    self.bet_summarizing = bet_summarizing.new()

    local result_shower = game.require "ui.ingame.result_shower"
    self.result_shower = result_shower.new(self.bet_area)

    local mini_record_shower = game.require 'ui.ingame.mini_record_shower'
    self.mini_record_shower = mini_record_shower.new()
end

function M:on_injected(bind)
    bind("button.click", self.btn_exit, self.exit_ivk)
    bind("shortcut.escape", self.btn_exit.gameObject, self.exit_ivk)
    bind("button.click", self.btn_rule, self.rule_ivk)

    game.utility.button_style.highlight_scale(self.btn_exit)
    game.utility.button_style.highlight_scale(self.btn_rule)
end

function M:load()
    self:super("load")
    
    self.player_info:load()
    self.player_info:set_parent(self.self_root, false)

    self.seats:load()
    self.seats:set_parent(self.seats_root, false)

    self.bet_operator:load()
    self.bet_operator:set_parent(self.bet_operator_root, false)

    self.bet_area:load()
    self.bet_area:set_parent(self.bet_area_root, false)

    self.others:load()
    self.others:set_parent(self.others_root, false)

    self.phase_shower:load()
    self.phase_shower:set_parent(self.phase_shower_root, false)

    self.bet_chip:load()
    self.bet_chip:set_parent(self.bet_chip_root, false)

    self.bet_summarizing:load()
    self.bet_summarizing:set_parent(self.bet_summarizing_root, false)

    self.result_shower:load()
    self.result_shower:set_parent(self.result_root, false)

    self.mini_record_shower:load()
    self.mini_record_shower:set_parent(self.record_shower_root, false)

    self.resumer:load()
    self.resumer:set_parent(self.resumer_root, false)
end

function M:exit_ivk()
    game.game_scene.leave()
end

function M:rule_ivk()
    game.router.push("/club.threecard.baccarat/manual")
end

return M